package com.polaris.live.im.db.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.polaris.live.App
import com.polaris.live.im.db.dao.TrackPushEntityDao
import com.polaris.live.im.db.entity.TrackPushEntity

/**
 * im的Database
 *
 * @author Created by lucas on 2024/1/1 07:50
 * @since 1.0.0
 */
@Database(
    entities = [
        TrackPushEntity::class
    ],
    version = 1,
    exportSchema = true
)
abstract class TrackDatabase : RoomDatabase() {

    abstract fun trackPushEntityDao(): TrackPushEntityDao

    companion object {

        private const val NAME_DATABASE = "track"

        val instance: TrackDatabase by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
            buildDatabase(App.instance)
        }

        private fun buildDatabase(context: Context): TrackDatabase {
            return Room.databaseBuilder(context, TrackDatabase::class.java, NAME_DATABASE).build()
        }
    }
}